<template>
 <div class="home">
    {{ message }}
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="banner in banners"
          :key="banner.id"
        >
          <img :src="banner.image" alt="" />
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/swiper-bundle.min.css'
import axios from 'axios'
export default {
  name: 'Home',
  data() {
    return {
      banners: [],
      message: 'hello'
    }
  },
  created() {
    setTimeout(() => {
      this.message = 'abc'
    }, 5000)
    axios
      .get('http://rap2api.taobao.org/app/mock/289055/api/banners')
      .then((res) => {
        const { banners } = res.data.data
        console.log('轮播图', banners)
        this.banners = banners
        this.$nextTick(() => {
          /* eslint-disable-next-line */
          new Swiper('.swiper-container', {
            loop: true, // 循环模式选项
            autoplay: {
              disableOnInteraction: false
            },

            // 如果需要分页器
            pagination: {
              el: '.swiper-pagination'
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev'
            }
          })
        })
      })
      .catch((err) => {
        console.log(err)
      })
  },
  updated() { // 在更新后执行
    console.log('更新后')
  }
}
</script>

<style lang="scss" scoped>
.test{
  width: 375px;
  font-size: 24px;
}
.swiper-container {
    width: 750px;
    height: 360px;
}
</style>
